//
//  SettingViewController.m
//  Manager
//
//  Created by 彭凯敏 on 15/8/18.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "SettingViewController.h"
#import "SettingCell.h"
#import "SettingCell2.h"
#import "LogUploadViewController.h"
@interface SettingViewController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(logout:) name:@"LogoutNoti" object:nil];
    

    [self homeBaseCtlSetTitle:@"设置" andWithBackType:BackZero];
    [_tableView setLineType:TableViewLineTypeAll];
    

}
- (void)logout:(NSNotification *)noti
{
    dispatch_async(dispatch_get_main_queue(), ^{
        HUDRemove;
        if ([noti.object isKindOfClass:[ErrorModel class]]) {
            ErrorModel *model = noti.object;
            [UIViewCategory FailShowWith:model];
        }
        else
        {
            
            
        }
    });
}
#pragma mark - UITableViewDelegate & UITableViewDataSource
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 0) {
        
    }
    if (indexPath.section == 1) {
        LogUploadViewController *vc = [[LogUploadViewController alloc]init];
        HideTabbar(vc);
        [self.navigationController pushViewController:vc animated:YES];

        
    }
    if (indexPath.section == 2) {

        KMAlertView *alert = [[KMAlertView alloc]initWithTitle:@"退出登录" message:@"确定要退出吗？" cancelButtonTitle:@"取消" clickButton:^(NSInteger index) {
            if (index == 1) {
                HUDShow(nil);
                
                [[UserLogic shareInstance]logoutReq];
            }
            
        } otherButtonTitles:@"退出"];
        
        
        [alert show];
        
        
        
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 13;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 || indexPath.section == 1) {
        
        static NSString *CellIdentifier = @"SettingCell";
        SettingCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell)
        {
            [tableView registerNib:[UINib nibWithNibName:@"SettingCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            
        }
        cell.cellImage.image = [UIImage imageNamed:@"set1"];

        if (indexPath.section == 0)
        {
            cell.cellImage.image = [UIImage imageNamed:@"set1"];
            cell.titleLabel.text = @"版本号";
            cell.cellArrow.hidden = YES;
            cell.versionLabel.text = BundleVersion;
        }
        if (indexPath.section == 1)
        {
            cell.cellImage.image = [UIImage imageNamed:@"set0"];
            cell.titleLabel.text = @"日志上传";
            cell.cellArrow.hidden = NO;
            cell.versionLabel.hidden = YES;
        }
        
        return cell;
    }
    else
    {
        static NSString *CellIdentifier = @"SettingCell2";
        SettingCell2 * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell)
        {
            [tableView registerNib:[UINib nibWithNibName:@"SettingCell2" bundle:nil] forCellReuseIdentifier:CellIdentifier];
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            
        }
        
        return cell;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
    
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
#ifdef __IPHONE_8_0
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
#endif
    
    
}


@end
